import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebInitParam;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/ConfigDemo",
        initParams = {
        @WebInitParam(name="email",value="1944@QQ.com"),
        @WebInitParam(name = "telephone",value = "155915")
})
public class ConfigDemoServlet extends HttpServlet {
    String servletName=null;
    ServletConfig config=null;
    String email =null;
    String telephone=null;

    @Override
    public void init(ServletConfig config) throws ServletException {
        this.config = config;
        servletName = config.getServletName();
        email = config.getInitParameter("email");
        telephone = config.getInitParameter("telephone");
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<head><title>配置对象</title></head>");
        out.println("Servlet名称："+servletName+"<br>");
        out.println("Email地址:"+email+"<br>");
        out.println("电话:"+telephone);
        out.println("</body></html>");
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        doGet(request,response);
    }
}
